package com.ellfors.module_first.main

import android.widget.Toast
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager
import com.ellfors.common.base.BaseActivity
import com.ellfors.common.base.EmptyViewModel
import com.ellfors.module_first.compose_test.TestComposeActivity
import com.ellfors.module_first.databinding.ActivityMainBinding
import com.ellfors.module_first.dialog_queue.DialogQueueActivity
import com.ellfors.module_first.edge_effect.EdgeEffectActivity
import com.ellfors.module_first.flow_layout.FlowLayoutActivity
import com.ellfors.module_first.index_rcv.IndexRcvActivity
import com.ellfors.module_first.multi_list_type.MultiListTypeActivity
import com.ellfors.module_first.picture_selector.PictureSelectorActivity
import com.ellfors.module_first.snap.SnapActivity
import com.ellfors.module_first.test.TestActivity
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch


class MainActivity : BaseActivity<ActivityMainBinding, EmptyViewModel>() {

    private val mAdapter by lazy {
        MainAdapter()
    }
    private val mDataList = mutableListOf(
        "Snap" to { SnapActivity.start(this) },
        "Test_Compose" to { TestComposeActivity.start(this) },
        "MultiListType" to { MultiListTypeActivity.start(this) },
        "IndexRecyclerView" to { IndexRcvActivity.start(this) },
        "EdgeEffectRecyclerView" to { EdgeEffectActivity.start(this) },
        "PictureSelector" to { PictureSelectorActivity.start(this) },
        "DialogQueue" to { DialogQueueActivity.start(this) },
        "FlowLayout" to { FlowLayoutActivity.start(this) },
        "Test" to { TestActivity.start(this) },
    )

    override fun initView() {
        hideTitleBarClose()
        showDeveloperView()
        showTitleBar("主页")

        mBinding.rcvMain.apply {
            layoutManager = LinearLayoutManager(this@MainActivity)
            adapter = mAdapter
        }
    }

    override fun initData() {
        lifecycleScope.launch {
            val emptyBlock = {
                Toast.makeText(this@MainActivity, "Empty", Toast.LENGTH_SHORT).show()
            }
            mutableListOf("Empty" to emptyBlock).also { mAdapter.submitList(it) }
            delay(200)
            mAdapter.submitList(mDataList)
        }
    }
}